package com.tjdx.projectsubmission.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class SubmitUtil {

    private final static String STORE_URL = "https://dev-env.wutongchain.com:49080/v2/tx/store?ledger=blkc2022";

    /**
     * 数据上报到梧桐链
     */
    public static String submitBlockchain(String data) {
        String dataId = null;
        Map<String, String> map = new HashMap<>();
        map.put("data", data);
        log.info("填报数据上报到梧桐链 - request:[{}]", JSONObject.toJSONString(map));
        String response = HttpUtil.post(STORE_URL, JSONObject.toJSONString(map));
        log.info("梧桐链response:[{}]", response);
        Map<String, Object> respMap = JSONObject.parseObject(response, Map.class);
        if (200==(int)respMap.get("state")) {
            dataId = (String) respMap.get("data");
        }
        return dataId;
    }










}
